<?php
namespace App\Plugins\Geetest;

/**
 * Geetest插件
 */
class Geetest extends \Phalcon\Mvc\Controller
{
	/**
	 * 开始
	 */
	public function start() {
		require_once APP_PATH . '/plugins/geetest/class.geetestlib.php';
		require_once APP_PATH . '/plugins/geetest/config.php';
		$GtSdk = new GeetestLib(CAPTCHA_ID, PRIVATE_KEY);
		// session_start();
		$gt_id = "sns";
		$status = $GtSdk->pre_process($gt_id);
		$_SESSION['gtserver'] = $status;
		$_SESSION['gt_id'] = $gt_id;
		echo $GtSdk->get_response_str();
		exit();
	}
	/**
	 * 获取验证状态
	 * @return boolean
	 */
	public function getStatus() {
		require_once APP_PATH . '/plugins/geetest/class.geetestlib.php';
		require_once APP_PATH . '/plugins/geetest/config.php';
		$GtSdk = new GeetestLib(CAPTCHA_ID, PRIVATE_KEY);
		$gt_id = $_SESSION['gt_id'];
		$result = false;
		if ($_SESSION['gtserver'] == 1) {
			$result = $GtSdk->success_validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode'], $gt_id);
			if ($result) {
				$result = true;
			}
		} else {
			if ($GtSdk->fail_validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode'])) {
				$result = true;
			}
		}
		return $result;
	}
}
?>